import java.util.Scanner;

public class Demo1 {
    private static boolean running = true;
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while (running){
                System.out.println("hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("t线程退出");
        });

        t.start();

        // 主线程中，让用户进行输入
        System.out.println("请输入一个整数：0表示让 t 线程终止");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 0){
            running = false;
        }
    }

}
